package com.chengshuang.log.factory;

import com.chengshuang.log.fuction.LogRecordFunction;
import com.chengshuang.log.fuction.LogRecordSnapshotFunction;
import java.util.HashMap;
import java.util.Map;

/**
 * 自定义函数工厂
 *
 * @author shuang.cheng
 * @date 2022/10/14
 */
public class FunctionFactory {

    /**
     * 在业务方法执行之前运行的自定函数
     */
    private static final Map<String, LogRecordFunction> BEFORE_FUNCTIONS = new HashMap<>();

    /**
     * 在业务方法执行之后运行的自定函数
     */
    private static final Map<String, LogRecordFunction> AFTER_FUNCTIONS = new HashMap<>();

    /**
     * 快照自定义函数
     */
    private static final Map<String, LogRecordSnapshotFunction> SNAPSHOT_FUNCTIONS = new HashMap<>();

    public static void putBeforeFunction(String functionName, LogRecordFunction myLogRecordFunction) {
        BEFORE_FUNCTIONS.put(functionName, myLogRecordFunction);
    }

    public static void putAfterFunction(String functionName, LogRecordFunction myLogRecordFunction) {
        AFTER_FUNCTIONS.put(functionName, myLogRecordFunction);
    }

    public static void putSnapshotFunction(String functionName, LogRecordSnapshotFunction myLogRecordSnapshotFunction) {
        SNAPSHOT_FUNCTIONS.put(functionName, myLogRecordSnapshotFunction);
    }

    public static LogRecordFunction getBeforeFunction(String functionName) {
        return BEFORE_FUNCTIONS.get(functionName);
    }

    public static Map<String, LogRecordFunction> getBeforeFunctions() {
        return BEFORE_FUNCTIONS;
    }

    public static LogRecordFunction getAfterFunction(String functionName) {
        return AFTER_FUNCTIONS.get(functionName);
    }

    public static LogRecordSnapshotFunction getSnapshotFunction(String functionName) {
        return SNAPSHOT_FUNCTIONS.get(functionName);
    }

    public static Map<String, LogRecordSnapshotFunction> getSnapshotFunctions() {
        return SNAPSHOT_FUNCTIONS;
    }

}
